<template>
  <div>
    <div class="header">
       <p>后台登录</p>
    </div>
    <div class="content">
       <div class="userloginModel">
           <label class="label2" for="账号">账号:</label>
            <input v-model="userName" type="text" name="" id=""><br>
            <label class="label2" for="密码">密码:</label>
            <input v-model="userpass" type="text">
       </div>
       <div class="userBtn">
           <p @click="userLogin()">确认</p>
       </div>
    </div>
    <div>
    </div>
  </div>
</template>

<script>
 import axios from 'axios'
export default {
  components: {

  },
  props: {

  },
  data() {
    return {
      userName:'',
      userpass:''
    };
  },
  created() {

  },
  mounted() {

  },
  methods: {
    //   登录
    userLogin(){
      const username = this.userName
      const password = this.userpass
       axios.get('/admin/login',{params:{username,password}}).then(res => {
             if(res.data.length != 0 && res.data[0].identity == 'superAdmin'){
                 localStorage.setItem("id", res.data[0]._id); 
                 localStorage.setItem("adminState", true); 
                 this.$router.push('/admin/index')
             }else if(res.data.length != 0 && res.data[0].identity == 'admin'){
                 localStorage.setItem("id", res.data[0]._id); 
                 localStorage.setItem("adminState", false); 
                 this.$router.push('/admin/index')
             }
        })
    }
  },
};
</script>
<style lang="less" scoped>
@import '../../assets/less/login/login.less';
</style>